import Item from "antd/lib/list/Item"

const initState = {
  loginIndex: '',
  loginObj: {},//哪个用户登陆的
  loginType: 0,//哪个状态登陆的
  loginName: '',//登陆用户名
  loginPass: "",//登陆密码
  jzpass: false,//记住密码
  scbList: [],//市场部列表
  scbList2: [],//市场部显示数据
  collegelist: [],//学院列表
  scbcollegelist: [],//市场部学院列表
  scbcollegelist2: [],//市场部学院列表
  jwList: [],//教务数据
  kclist: [],
  img: '',
  imgtype: '',
  version: {title:'',logo:'',login_root:'',company_name:'',duration:''}, //版本信息
  employee: [], //员工信息
  roleList:[],//角色权限
}

function administratorReducer(state = initState, action) {
  JSON.parse(JSON.stringify(state))
  let { type, payload } = action
  switch (type) {
    case 'getLogin':
      {
        state.loginIndex = payload.code
        if (payload.obj) {
          state.loginObj = payload.obj
        }
        var obj1 = JSON.parse(JSON.stringify(state));
        return { ...obj1 };
      }
    case 'setloginName':
      {
        state.loginName = payload
        var obj2 = JSON.parse(JSON.stringify(state));
        return { ...obj2 };
      }
    case 'setloginPass':
      {
        state.loginPass = payload
        var obj3 = JSON.parse(JSON.stringify(state));
        return { ...obj3 };
      }
    case 'setjzpass':
      {
        state.jzpass = payload
        var obj4 = JSON.parse(JSON.stringify(state));
        return { ...obj4 };
      }
    case 'setempty':
      {
        state.loginName = ''
        state.loginPass = ''
        var obj5 = JSON.parse(JSON.stringify(state));
        return { ...obj5 };
      }
    case 'getscblist':
      {
        state.scbList = payload.data
        state.scbcollegelist = payload.data2
        // console.log(state.scbList);
        state.scbList2 = payload.brr
        var obj6 = JSON.parse(JSON.stringify(state));
        return { ...obj6 };
      }
    case 'getcollegelist':
      {
        state.collegelist = payload.data
        var obj7 = JSON.parse(JSON.stringify(state));
        return { ...obj7 };
      }
    case 'addstudent':
      {
        var obj8 = JSON.parse(JSON.stringify(state));
        return { ...obj8 };
      }
    case 'getjwlist':
      {
        var obj9 = JSON.parse(JSON.stringify(state));
        return { ...obj9 };
      }
    case 'getkclist':
      {

        state.kclist = JSON.parse(payload.info.list)

        var obj10 = JSON.parse(JSON.stringify(state));
        return { ...obj10 };
      }
    case 'setclass':
      {
        var obj11 = JSON.parse(JSON.stringify(state));
        return { ...obj11 };
      }
    case 'diststudent':
      {
        var obj12 = JSON.parse(JSON.stringify(state));
        return { ...obj12 };
      }
    case 'amendstudent':
      {
        var obj13 = JSON.parse(JSON.stringify(state));
        return { ...obj13 };
      }
    case 'setimage':
      {
        state.img = payload

        var obj14 = JSON.parse(JSON.stringify(state));
        return { ...obj14 };
      }
    case 'setimgtype':
      {
        state.imgtype = payload

        var obj15 = JSON.parse(JSON.stringify(state));
        return { ...obj15 };
      }
      case "getVersion": {
              state.version = payload;
              var obj16 = JSON.parse(JSON.stringify(state));
              return { ...obj16 };
            }
            case "editVersionTitle": {
              state.version.title = payload;
              var obj17 = JSON.parse(JSON.stringify(state));
              return { ...obj17 };
            }
            case "uploadLogo": {
              state.version.logo = payload;
              var obj18 = JSON.parse(JSON.stringify(state));
              return { ...obj18 };
            }
            case "editVersionLoginRoot": {
              state.version.login_root = payload;
              var obj19 = JSON.parse(JSON.stringify(state));
              return { ...obj19 };
            }
            case "editVersionCompanyName": {
              state.version.company_name = payload;
              var obj20 = JSON.parse(JSON.stringify(state));
              return { ...obj20 };
            }
            case "editVersionDuration": {
              state.version.duration = payload;
              var obj21 = JSON.parse(JSON.stringify(state));
              return { ...obj21 };
            }
            case "getEmployeeList": {
              state.employee = payload;
              var obj22 = JSON.parse(JSON.stringify(state));
              return { ...obj22};
            }
            case "addEmployeeList": {
              state.employee.push(payload);
              var obj23 = JSON.parse(JSON.stringify(state));
              return { ...obj23 };
            }
            case "importEmployeeDate": {
              payload.forEach((item) => {
                state.employee.push({
                  id: Number(state.employee[state.employee.length - 1].id) + 1,
                  number: item.number,
                  name: item.name,
                  sex: item.sex,
                  age: item.age,
                  identity:item.identity,
                  userRoot: item.userRoot,
                  phone: item.phone,
                  email: item.email,
                  college: item.college,
                  campus: item.campus,
                  stage: item.stage,
                  position: item.position,
                  state:item.state,
                  remark:item.remark
                });
              });
              var obj24 = JSON.parse(JSON.stringify(state));
              return { ...obj24 };
            }
            case "editEmployeeInfo": {
                state.employee.forEach((item:any)=>{
                  if(item.id === payload.id){
                    item.name = payload.name;
                    item.sex = payload.sex;
                    item.age = payload.age;
                    item.identity = payload.identity;
                    item.userRoot = payload.userRoot;
                    item.phone = payload.phone;
                    item.email = payload.email;
                    item.college = payload.college;
                    item.campus = payload.campus;
                    item.stage = payload.stage;
                    item.position = payload.position;
                    item.state = payload.state;
                    item.remark = payload.remark;
                  }
                })
                var obj25 = JSON.parse(JSON.stringify(state));
                return { ...obj25 };
              }
              case "DelEmployee": {
                state.employee.forEach((item:any,index:any)=>{
                  if(item.id === payload.id){
                    state.employee.splice(index,1);
                  }
                })
                var obj26 = JSON.parse(JSON.stringify(state));
                return { ...obj26 };
              }
              case "getRoleList": {
                state.roleList = payload;
                var obj27 = JSON.parse(JSON.stringify(state));
                return { ...obj27 };
              }
              case "addRoleList": {
                state.roleList[state.roleList.length] = {
                  "id":state.roleList.length+1,
                  "role":payload.role,
                  "explain":payload.explain,
                  "child_admin":payload.child_admin,
                  "privilege":payload.privilege
                };
                var obj28 = JSON.parse(JSON.stringify(state));
                return { ...obj28 };
              }
    default:
      break;
  }
  return state;
}

export default administratorReducer;